package gui.user;

import gui.GUI;

import java.awt.event.*;
import java.awt.geom.Point2D;
import java.util.ArrayList;

import math.Vector2D;

/**
 * @author Ryan Hill
 */
public class User 
{
	
	private ArrayList<Integer> keys; //keys currently being pressed
	private Point2D mouse; //mouse position
	private int button; //mouse button being clicked
	
	private Point2D mouseMove;

	public User()
	{
		keys = new ArrayList<Integer>();
		button = -1;
		mouseMove = new Point2D.Double();
	}
	
	
	/**
	 * @return mouse location, null if not held down
	 */
	public Point2D getMousePos()
	{
		return mouse;
	}
	
	public Point2D getMouseMove()
	{
		return mouseMove;
	}
	/**
	 * @return button on mouse being held down, -1 if not held down
	 */
	public int getButton()
	{
		return button;
	}
	
	/**
	 * Click the mouse and notify the user
	 * 
	 * @param b button clicked
	 * @param v location of mouse
	 */
	public void mouseClick(int b, Point2D v)
	{
		button = b;
		mouse = v;
	}
	
	/**
	 * Release all mouse data
	 */
	public void mouseRelease()
	{
		button = -1;
		mouse = null;
	}
	
	public void mouseMove(Point2D v)
	{
		mouseMove = v;
	}
	
	/**
	 * Press a key down and notify the user
	 * 
	 * @param key the key code for the key being pressed
	 */
	public void keyPressed(int key)
	{
		if (!isPressed(key))
			keys.add(key);
	}
	
	/**
	 * Release a key and notify the user
	 * 
	 * @param key the key code for the key being released
	 */
	public void releaseKey(int keycode)
	{
		keys.remove(new Integer(keycode));
	}
	public boolean isPressed(int keycode)
	{
		return (keys.indexOf(keycode) >= 0);
	}
}
